package org.fujene.memoryblock.structure;

public class MemType{
	private String name;
	private MemoryTypes type;
	private int repetition;
	@SuppressWarnings("rawtypes")
	private SerializableNumber[] number;

	public MemType(String name, int repetition, MemoryTypes type){
		this.name = name;
		this.repetition = repetition;
		this.type = type;
		this.number = new SerializableNumber[this.repetition];
	}

	public int size(){
		return number[0].length();
	}

	public int totalSize(){
		int totalval = 0;
		for(int i = 0; i < repetition; i++)
			totalval += number[i].length();
		return totalval;
	}

	public void setClass(SerializableNumber<?> num){
		for(int i = 0; i < number.length; i++)
			number[i] = num.clone();
	}

	public SerializableNumber<?> getClassType(int index){
		return number[index];
	}

	public MemoryTypes getType(){
		return type;
	}

	public byte[] getBytes(int index){
		if(index >= repetition) return null;
		return number[index].toByte();
	}

	public byte[] getConcatBytes(){
		byte[] output = new byte[totalSize()];
		byte[] temp;
		int current = 0;

		for(int i = 0; i < repetition; i++){
			temp = number[i].toByte();
			System.arraycopy(temp, 0, output, current, temp.length);
			current += temp.length;
		}

		return output;
	}
	
	public String getName() {
		return name;
	}

	@Override
	public String toString(){
		return name;
	}
}
